package com.spzx.product.api.fallback;

import com.spzx.common.core.domain.R;
import com.spzx.product.api.SkuStockFeignClient;
import com.spzx.product.api.domain.vo.SkuLockVo;
import com.spzx.product.api.domain.vo.SkuStockVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;

import java.util.List;

/**
 * @ClassName SkuStockFeignClientFallbackFactory
 * @Author 波
 * @Date 2024/8/5 20:35
 */
@Slf4j
public class SkuStockFeignClientFallbackFactory implements FallbackFactory<SkuStockFeignClient> {
    @Override
    public SkuStockFeignClient create(Throwable cause) {
        log.error("商品服务调用失败"+cause.getMessage());
        return new SkuStockFeignClient() {
            @Override
            public R<SkuStockVo> getSkuStockVo(Long skuId, String source) {
                return R.fail("获取Sku库存信息失败:" + cause.getMessage());
            }

            @Override
            public R<String> checkAndLock(String orderNo, List<SkuLockVo> skuLockVoList, String source) {
                return R.fail("锁定库存失败:" + cause.getMessage());

            }
        };
    }
}
